package com.zhuss.util;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class HeaderUtil {
	
	public static ThreadLocal<Integer> systemTl = new ThreadLocal<>();
	
	public static ThreadLocal<Long> userIdTl = new ThreadLocal<>();
	
	
	public static String getCurrentToken() {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest();
		String token = request.getHeader("token");
		return token;
	}
	
	public static Long getCurrentUserId() {
//		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
//				.getRequest();
//		String userIdStr = request.getHeader("userId");
//		Long userId = null;
//        if (userIdStr != null) {
//        	userId = Long.valueOf(userIdStr);
//        }
		Long userId = userIdTl.get();
		return userId;
	}
	
	public static Integer getCurrentSystem() {
//		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
//				.getRequest();
//		Integer system = Integer.parseInt(request.getHeader("system"));
		Integer system = systemTl.get();
		return system;
	}
}
